package com.cfilmcloud.learn.demo;

import com.cfilmcloud.learn.domain.Learn;
import org.assertj.core.util.Lists;

import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * Description: 重复<br>
 * 1、…<br>
 * 2、…<br>
 * Implement: <br>
 * 1、…<br>
 * 2、…<br>
 * 
 * @author mengxy[孟祥元][mengxiangyuan@cfilmcloud.com]
 * Created by edz on 2017/7/26.
 */
public class DemoDistinct {

    public static void main(String[] args) {
        //生成器
        final Supplier<Learn> learnSupplier = Learn::new;

        //mock
        final Function<String, Learn> mockLearn = (x) -> {
            Learn learn = learnSupplier.get();
            learn.setId("id_" + x);
            learn.setName("name_" + x);
            learn.setQuestion("question_" + x);
            return learn;
        };

        final List<Learn> learns = Lists.newArrayList(
                mockLearn.apply("2"),
                mockLearn.apply("2"),
                mockLearn.apply("3"));

        /*****去重后比较前后List的大小****/
        int size = learns.stream().map(Learn::getId).distinct().collect(Collectors.toList()).size();

        if (learns.size() == size) {
            System.err.println("不存在ID重复的对象");
        } else {
            System.err.println("存在ID重复的对象");
        }
    }
}
